package com.vf.admin.miaodong.controller.fiwork;

import com.vf.admin.common.BaseController;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.splitpage.SplitPageBean;

import com.vf.admin.miaodong.entity.AppBiaoqian;
import com.vf.admin.miaodong.service.AfterBiaoqianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/manage/app/biaoqian")
public class AppBiaoQianManageController extends BaseController {


    @Autowired
    AfterBiaoqianService afterBiaoqianService;

    @RequestMapping("/page")
    public String page(SplitPageBean splitPage, String name, String leixing, String country) {
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("name", name);
            params.put("leixing", leixing);
            params.put("country", country);
            List<AppBiaoqian> page = afterBiaoqianService.list(params, splitPage);
            request.setAttribute("list", page);
            request.setAttribute("splitPage", splitPage);
            request.setAttribute("name", name);
            request.setAttribute("leixing", leixing);
            request.setAttribute("country", country);
            return this.sucess("/web/manage/app/biaoqian/list");
        } catch (Exception e) {
            e.printStackTrace();
            return this.error("系统繁忙，请稍后再试");
        }
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Result saveOrUpate(AppBiaoqian params) {
        if (params.getId() == null) {
            params.setCreatetime(new Date());
            params.setState(1);
        }
        afterBiaoqianService.save(params);
        return sucessJSON("操作成功");
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Result delete(Integer id) {
        afterBiaoqianService.del(id);
        return sucessJSON("操作成功");
    }

    @RequestMapping("/info")
    public String info(Integer id, Integer type) {
        AppBiaoqian appCountry = afterBiaoqianService.get(id);
        request.setAttribute("obj", appCountry);

        if(type == 1) {
            return this.sucess("/web/manage/app/biaoqian/detail");
        } else {
            return this.sucess("/web/manage/app/biaoqian/edit");
        }

    }

    @RequestMapping("/gotoAdd")
    public String gotoAdd() {
        return this.sucess("/web/manage/app/biaoqian/add");
    }
}
